<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit :isheader="isheader">
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button
                            alias="insAppCollectAdd"
                            :butn-icon="'plus'"
                            :butn-type="'primary'"
                            :show-no-right="true"
                            @click="add"
                        >{{$ti18('rxList.newBtn','新建')}}
                        </rx-button
                        >
                        <a-dropdown
                            v-if="removeEnable && selectedRowKeys.length > 0 && editEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item
                                    key="1"
                                    @click="editOne"
                                    v-if="editEnable && selectedRowKeys.length > 0"
                                    alias="formRuleEdit"
                                    :butn-type="'primary'"
                                    :show-no-right="false"
                                >
                                    <a-icon type="edit"/>
                                    {{$ti18('rxList.editBtn','编辑')}}
                                </a-menu-item>
                                <a-menu-item
                                    key="2"
                                    @click="delByIds(selectedRowKeys)"
                                    v-if="removeEnable && selectedRowKeys.length > 0"
                                    alias="formRuleDelete"
                                    :butn-type="'danger'"
                                    :show-no-right="false"
                                >
                                    <a-icon type="delete"/>
                                    {{$ti18('rxList.delBtn','删除')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
                </div>
                <div btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="closeSearchbar">
                    <a-form :layout="colLayout">
                        <a-row :gutter="24">
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.name','应用名称')">
                                    <a-input :placeholder="i18n('form.name','应用名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.type','类型')">
                                    <a-radio-group
                                        v-model="queryParam.Q_TYPE__S_EQ"
                                        v-decorator="['queryParam.Q_TYPE__S_LK', { rules: [{ required: true, message: i18n('form.type','类型','select') }] }]"
                                    >
                                        <a-radio value="interior">{{i18n('form.interior','内部')}}</a-radio>
                                        <a-radio value="outside">{{i18n('form.outside','外部')}}</a-radio>
                                    </a-radio-group>
                                </a-form-item>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :bordered="isBorder"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-portal/portal/core/insAppCollect/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10', '30', '40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                  <span slot="type" slot-scope="{ text, record }">
                    <a-tag :color="typeMap[text].color">
                      <span>{{ typeMap[text].text }}</span>
                    </a-tag>
                  </span>
                    <span slot="appType" slot-scope="{ text, record }">
                    <a-tag :color="appTypeMap[text].color">
                      <span>{{ appTypeMap[text].text }}</span>
                    </a-tag>
                  </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span v-if="editEnable && showBtn(false)" @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                        <span v-if="removeEnable && showBtn(false)" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>

import InsAppCollectApi from '@/api/portal/core/insAppCollect'
import InsAppCollectEdit from './InsAppCollectEdit'
import {BaseList} from "@lowcode/jpaas-common-lib"

export default {
    name: 'InsAppCollectList',
    mixins: [BaseList],
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 40,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'},
                },
                {title: this.i18n('form.name','应用名称'), dataIndex: 'name', width: 100},
                {title: this.i18n('form.type','类型'), dataIndex: 'type', width: 50, scopedSlots: {customRender: 'type'}},
                {title: this.i18n('form.default','默认'), dataIndex: 'appType', width: 50, scopedSlots: {customRender: 'appType'}},
                {title: this.i18n('form.url','应用链接地址'), dataIndex: 'url', width: 200},
                {title: this.$ti18('rxList.action','操作'), width: 60, dataIndex: 'action', scopedSlots: {customRender: 'action'}},
            ],
            component: InsAppCollectEdit,
            comment: this.i18n('list.comment','常用应用'),
            widthHeight: ['1050px', '600px'],
            typeMap: {
                interior: {color: 'green', text: this.i18n('form.interior','内部')},
                outside: {color: 'red', text: this.i18n('form.outside','外部')},
                link: {color: 'yellow', text: this.i18n('form.link','链接')},
            },
            appTypeMap: {
                default: {color: 'red', text: this.i18n('form.yes','是')},
                custom: {color: 'green', text: this.i18n('form.no','否')},
            },
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"InsAppCollect",key);
        },
        delById(ids) {
            return InsAppCollectApi.del({ids: ids.join(',')})
        },
        getListByParams(parameter) {
            return InsAppCollectApi.query(parameter)
        },
        search() {
            this.$refs.table.loadData()
        },
        cancel() {
            this.resetSearch()
        },
        closeSearchbar() {
            //关闭过滤弹窗；（点击X触发）
            this.fitSearch = false;
        },
    },
}
</script>
<style scoped>

</style>

